<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class GoodsCate extends Base
{
    protected $insert = ['addtime'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    
    public function getImgTextAttr($value,$data){
        return $data['pic'] ? cdnurl($data['pic'],true) : "";
    }
     /**
     * @description: 代驾商名称
     * @param {*} $value
     * @param {*} $data
     * @return {*}
     */    
    public function getAgentNameTextAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('name');
    }
    
    public function lists(){
        $list = (new \app\common\model\GoodsCate())->where(['pid' => 0,'is_del' => 0])->select()->toArray();
        foreach ($list as $key => &$value) {
            $value['list'] =  (new \app\common\model\GoodsCate())->where(['pid' => $value['id']])->select()->toArray();
        }
        return $list;
    }
}
